<template>
  <div class="example">
    <p>思考题：如何自行实现一个过渡功能？</p>
    <div class="box" :class="className" v-show="isShow"></div>
    <div class="btn">
      <button @click="handleClick">{{ isShow ? '隐藏' : '显示' }}</button>
    </div>
  </div>
</template>

<script>
/**
 * 自己实现一个过渡效果
 */

export default {
  data() {
    return {
      isShow: true,
      className: ''
    }
  },
  watch: {
    isShow(val) {
      if (val) {
        this.className = 'fade-enter-active fade-enter-to';
      } else {
        this.className = 'fade-leave-active fade-leave-to';
      }
    }
  },
  methods: {
    handleClick() {
      this.isShow = !this.isShow
    }
  }
}
</script>

<style lang="less" scoped>
.fade-enter-active, .fade-leave-active {
  transition: opacity 10s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  opacity: 0;
}
</style>
